<template>
  <el-card shadow="never">
    <template #header>
      <div class="card-header">
        <el-form :inline="true" :model="params.entity"
                 style="padding-bottom: 0px;">
          <el-form-item label="代理人姓名">
            <el-input v-model="params.entity.adminName"
                      placeholder="请输入代理姓名"/>
          </el-form-item>
          <el-form-item label="手机号码">
            <el-input v-model="params.entity.phone"
                      placeholder="请输入手机号码"/>
          </el-form-item>
          <!--          <el-form-item label="区域">-->
          <!--            <el-input v-model="params.entity.area"-->
          <!--                      placeholder="请输入区域"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="支付金额">-->
          <!--            <el-input v-model="params.entity.payMoney"-->
          <!--                      placeholder="请输入支付金额"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="支付时间">-->
          <!--            <el-input v-model="params.entity.payTime"-->
          <!--                      placeholder="请输入支付时间"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="备注">-->
          <!--            <el-input v-model="params.entity.payRemark"-->
          <!--                      placeholder="请输入备注"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="是否支付 0-否 1-是">-->
          <!--            <el-input v-model="params.entity.payFlag"-->
          <!--                      placeholder="请输入是否支付 0-否 1-是"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="当前等级">-->
          <!--            <el-input v-model="params.entity.proxyOraCategoryId"-->
          <!--                      placeholder="请输入当前等级"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="申请等级">-->
          <!--            <el-input v-model="params.entity.proxyCategoryId"-->
          <!--                      placeholder="请输入申请等级"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="审核状态 0-待审核 1-审核通过 2-审核不通过">-->
          <!--            <el-input v-model="params.entity.verifyFlag"-->
          <!--                      placeholder="请输入审核状态 0-待审核 1-审核通过 2-审核不通过"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="审核时间">-->
          <!--            <el-input v-model="params.entity.verifyTime"-->
          <!--                      placeholder="请输入审核时间"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="审核备注">-->
          <!--            <el-input v-model="params.entity.verifyRemark"-->
          <!--                      placeholder="请输入审核备注"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="状态 0-停用 1-启用 2-备用">-->
          <!--            <el-input v-model="params.entity.statusFlag"-->
          <!--                      placeholder="请输入状态 0-停用 1-启用 2-备用"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="是否删除 0-否 1-是">-->
          <!--            <el-input v-model="params.entity.delFlag"-->
          <!--                      placeholder="请输入是否删除 0-否 1-是"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="创建人">-->
          <!--            <el-input v-model="params.entity.createUser"-->
          <!--                      placeholder="请输入创建人"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="创建时间">-->
          <!--            <el-input v-model="params.entity.createTime"-->
          <!--                      placeholder="请输入创建时间"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="修改时间">-->
          <!--            <el-input v-model="params.entity.updateTime"-->
          <!--                      placeholder="请输入修改时间"/>-->
          <!--          </el-form-item>-->
          <!--          <el-form-item label="备注">-->
          <!--            <el-input v-model="params.entity.remark"-->
          <!--                      placeholder="请输入备注"/>-->
          <!--          </el-form-item>-->
          <el-form-item>
            <el-button type="primary" :icon="Search" @click="searchData">查询
            </el-button>
            <!--            <el-button type="primary" :icon="Plus" @click="addDialog">新增-->
            <!--            </el-button>-->
          </el-form-item>
        </el-form>
      </div>
    </template>
    <el-table v-loading="loading"
              :data="tableData.list" style="width: 100%" height="500"
              :default-sort="{ prop: 'date', order: 'descending' }"
              @selection-change="handleSelectionChange">
<!--      <el-table-column fixed type="selection" width="55"/>-->
<!--      <el-table-column prop="id" label=""-->
<!--                       show-overflow-tooltip/>-->

      <el-table-column prop="verifyFlagName" fixed label="审核状态" width="140"
                       show-overflow-tooltip/>

      <el-table-column prop="proxyOraCategoryName" fixed label="代理等级" width="180">
        <template #default="scope">
          {{scope.row.proxyOraCategoryName}} => <span style="color: red">{{scope.row.proxyCategoryName}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column prop="proxyCategoryName" label="申请代理等级" show-overflow-tooltip/>-->
      <el-table-column prop="adminName" label="代理人姓名" fixed width="120"/>
<!--      <el-table-column prop="name" label="称呼" fixed show-overflow-tooltip/>-->
      <el-table-column prop="phone" label="手机号码" width="120"/>
      <el-table-column prop="area" label="代理区域" show-overflow-tooltip/>

      <el-table-column prop="payMoney" label="支付金额" show-overflow-tooltip/>
      <el-table-column prop="payTime" label="支付时间"
                       show-overflow-tooltip/>
      <el-table-column prop="payRemark" label="支付备注" show-overflow-tooltip/>
      <el-table-column prop="payFlagName" label="是否支付"
                       show-overflow-tooltip/>


      <el-table-column prop="verifyTime" label="审核时间"
                       show-overflow-tooltip/>
      <el-table-column prop="verifyRemark" label="审核备注"
                       show-overflow-tooltip/>
<!--      <el-table-column prop="statusFlagName" label="状态" width="80" show-overflow-tooltip/>-->
      <!--      <el-table-column prop="delFlag" label="是否删除 0-否 1-是"-->
      <!--                       show-overflow-tooltip/>-->
      <!--      <el-table-column prop="createUser" label="创建人"-->
      <!--                       show-overflow-tooltip/>-->
      <!--      <el-table-column prop="createTime" label="创建时间"-->
      <!--                       show-overflow-tooltip/>-->
      <!--      <el-table-column prop="updateTime" label="修改时间"-->
      <!--                       show-overflow-tooltip/>-->
      <!--      <el-table-column prop="remark" label="备注"-->
      <!--                       show-overflow-tooltip/>-->

      <el-table-column fixed="right" label="操作" width="180"
                       v-if="userInfo.userType == 0">
<!--        <template #header>-->
<!--          <el-input v-model="params.search" @keyup.enter.native="searchData"-->
<!--                    placeholder="搜索角色名称/介绍"/>-->
<!--        </template>-->
        <template #default="scope">
<!--          <el-button link type="danger" :icon="Delete" size="small"-->
<!--                     @click="showDeleteDialog(scope.row.id)">删除-->
<!--          </el-button>-->
          <el-button link type="primary" v-if="scope.row.verifyFlag==0" :icon="Edit" size="small"
                     @click="editDialog(scope.row)">审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination v-model:currentPage="params.current"
                   v-model:page-size="params.size"
                   :page-sizes="[100, 200, 300, 400]"
                   layout="sizes, prev, pager, next" :total="tableData.total"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"/>
  </el-card>

  <!-- 新增或者修改页面-->
  <SysAdminApplyProxyAddOrEdit
      @closeEditDialog="closeEditDialog"
      :addOrEditVisible="addOrEditVisible"
      :ruleForm="ruleForm"
      :addDataType="addDataType"></SysAdminApplyProxyAddOrEdit>
</template>

<script lang="ts" setup>
import {ElTable, ElMessage, ElMessageBox} from 'element-plus'
import {onMounted, computed, reactive, ref} from 'vue'
import {Params, Result} from "@/apis/model/common/common.interfaces"
import {
  Delete,
  Edit,
  Search,
  Share,
  Upload,
  Plus,
  Setting
} from '@element-plus/icons-vue'
import SysAdminApplyProxyAddOrEdit from './sysAdminApplyProxyAddOrEdit.vue'
import {SysAdminApplyProxy}
  from "@/apis/model/proxy/SysAdminApplyProxyModel";
import {
  deleteSysAdminApplyProxyById,
  sysAdminApplyProxyPage
} from "@/apis/http/proxy/SysAdminApplyProxyHttp";
import {userStore} from "@/store";

const store = userStore();
const userInfo = store.userInfo;

// 查询
const params: Params = reactive({
  current: 1 as number,
  size: 10 as number,
  search: '' as string,
  entity: {
    userType: userInfo.userType
  } as SysAdminApplyProxy
})

const ruleForm = ref<SysAdminApplyProxy>({} as SysAdminApplyProxy)

// AddOrEditVisible
const addOrEditVisible = ref(false)

// table 表数据
const tableData: any = ref({});

// 加载数据
const loading = ref(true)
const addDataType = ref('add');

/**
 * 初始化数据
 */
const initList = () => {
  loading.value = true
  sysAdminApplyProxyPage(params).then((res: Result) => {
    const code = res.code
    const message = res.message
    const data = res.data
    if (code == 200) {
      tableData.value = data
    }
    loading.value = false
  })
}

/**
 * search 查询数据
 */
const searchData = () => {
  initList()
}

/**
 * 每页数据量改变查询数据
 * @param val
 */
const handleSizeChange = (val: number) => {
  params.size = val
  initList()
}

/**
 * 分页查询数据
 * @param val
 */
const handleCurrentChange = (val: number) => {
  params.current = val
  initList()
}

/**
 * 添加弹出
 */
const addDialog = () => {
  addOrEditVisible.value = true
  ruleForm.value = {} as SysAdminApplyProxy
  addDataType.value = 'add'
}

//修改弹窗
const editDialog = (row:
                        SysAdminApplyProxy
) => {
  addOrEditVisible.value = true
  ruleForm.value = row
  addDataType.value = 'edit'
}

// 关闭修改弹窗
const closeEditDialog = (e: any) => {
  addOrEditVisible.value = e.addOrEditVisible
  if (e.refushList = true) {
    params.current = 1;
    initList();
  }
}

/**
 * 弹出删除对话框
 */
const showDeleteDialog = (id: number) => {
  ElMessageBox.confirm(
      '是否删除?',
      '提醒',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  ).then(() => {
    deleteSysAdminApplyProxyById(id).then((res: Result) => {
      const code = res.code;
      if (code == 200) {
        ElMessage({
          message: '删除数据成功！',
          type: 'success',
        })
        initList();
      } else {
        ElMessage.error('删除数据失败！');
      }
    })
  }).catch(() => {
    // ElMessage({
    //   type: 'info',
    //   message: 'Delete canceled',
    // })
  })
}

onMounted(() => {
  initList()
})
</script>

<style>
</style>
